//#if net_2_0
//#pragma warning disable 1591, 162
//#endif
// created by jay 0.7 (c) 1998 Axel.Schreiner@informatik.uni-osnabrueck.de

					// line 1 "Parser.jay"

//
// Parser.jay: The Parser for MyJScript
//

using System;
using System.Collections.Generic;
using Microsoft.Scripting;
using Microsoft.Scripting.Ast;
using Microsoft.Scripting.Actions;
using Microsoft.Scripting.Hosting;
using Microsoft.Scripting.Runtime;


namespace MyJScript.Compiler
{
	/// <summary>
	///    The MyJScript Parser
	/// </summary>
	public class Parser : GenericParser {
		
		/// <summary>
		/// Report errors encountered.
		/// </summary>	
		private Report report;
		
		/// <summary>
		/// Code generator
		/// </summary>
		private Generator generator;	

        /// <summary>
        /// Function arguments
        /// </summary>
        private List<String> arguments;
                		
		/// <summary>
		/// Result of generation
		/// </summary>
		public LambdaExpression Result
		{
			get { return result; }
		}
		private LambdaExpression result;

					// line 53 "-"

  /// <summary>
  /// simplified error message.
  /// </summary>
  /// <param name="state">state</param>
  /// <param name="token">token</param>
  /// <param name="tokenValue">tokenValue</param>
  /// <param name="expecting">expecting states</param>
  public void yyerror (int state, int token, object tokenValue, string[] expecting) {
    report.Error(lexer.Location, state, token, tokenValue, expecting); 
  }

  /// <summary>
  /// debugging support, requires the package jay.yydebug.
  /// Set to null to suppress debugging messages.
  /// </summary>
//t  protected yydebug.yyDebug debug;

  protected static  int yyFinal = 1;
//t  public static  string [] yyRule = {
//t    "$accept : program",
//t    "$$1 :",
//t    "program : $$1 opt_list_function_statement",
//t    "opt_list_function_statement : list_function_statement",
//t    "opt_list_function_statement :",
//t    "list_function_statement : list_function_statement function_or_statement",
//t    "list_function_statement : function_or_statement",
//t    "function_or_statement : function_decl",
//t    "function_or_statement : statement",
//t    "$$2 :",
//t    "$$3 :",
//t    "function_decl : FUNCTION IDENT $$2 LPAR opt_list_param RPAR $$3 block",
//t    "$$4 :",
//t    "$$5 :",
//t    "function_decl_expr : FUNCTION $$4 LPAR opt_list_param RPAR $$5 block",
//t    "opt_list_param : list_param",
//t    "opt_list_param :",
//t    "list_param : list_param CM IDENT",
//t    "list_param : IDENT",
//t    "$$6 :",
//t    "block : LBRA $$6 opt_list_statement RBRA",
//t    "opt_list_statement : list_statement",
//t    "opt_list_statement :",
//t    "list_statement : list_statement statement",
//t    "list_statement : statement",
//t    "statement : using_library",
//t    "statement : decl_var",
//t    "statement : setvar",
//t    "statement : if_else",
//t    "statement : while",
//t    "statement : proc_call",
//t    "statement : return",
//t    "using_library : USING IDENT SC",
//t    "decl_var : VAR IDENT opt_init SC",
//t    "opt_init : EQ expr",
//t    "opt_init :",
//t    "setvar : IDENT EQ expr SC",
//t    "setvar : expr DOT IDENT EQ expr SC",
//t    "$$7 :",
//t    "if_else : IF LPAR cond_expr RPAR block_or_statement $$7 ELSE block_or_statement",
//t    "if_else : IF LPAR cond_expr RPAR block_or_statement",
//t    "$$8 :",
//t    "funct_call : IDENT LPAR $$8 opt_list_expr RPAR",
//t    "$$9 :",
//t    "funct_call : expr DOT IDENT LPAR $$9 opt_list_expr RPAR",
//t    "$$10 :",
//t    "new_object : NEW IDENT LPAR $$10 opt_list_expr RPAR",
//t    "new_object : LBRA RBRA",
//t    "proc_call : funct_call SC",
//t    "while : WHILE LPAR cond_expr RPAR block_or_statement",
//t    "return : RETURN expr SC",
//t    "return : RETURN SC",
//t    "block_or_statement : block",
//t    "block_or_statement : statement",
//t    "cond_expr : expr EQEQ expr",
//t    "cond_expr : expr NE expr",
//t    "cond_expr : expr GT expr",
//t    "cond_expr : expr LS expr",
//t    "cond_expr : expr GTEQ expr",
//t    "cond_expr : expr LSEQ expr",
//t    "expr : expr PLUS expr",
//t    "expr : expr MULT expr",
//t    "expr : expr MINUS expr",
//t    "expr : expr DIV expr",
//t    "expr : funct_call",
//t    "expr : function_decl_expr",
//t    "expr : new_object",
//t    "expr : literal",
//t    "expr : variable",
//t    "literal : NUMBER",
//t    "literal : STRING",
//t    "variable : IDENT",
//t    "variable : expr DOT IDENT",
//t    "opt_list_expr : list_expr",
//t    "opt_list_expr :",
//t    "list_expr : list_expr CM expr",
//t    "list_expr : expr",
//t  };
  protected static  string [] yyName = {    
    "end-of-file",null,null,null,null,null,null,null,null,null,null,null,
    null,null,null,null,null,null,null,null,null,null,null,null,null,null,
    null,null,null,null,null,null,null,null,null,null,null,null,null,null,
    null,null,null,null,null,null,null,null,null,null,null,null,null,null,
    null,null,null,null,null,null,null,null,null,null,null,null,null,null,
    null,null,null,null,null,null,null,null,null,null,null,null,null,null,
    null,null,null,null,null,null,null,null,null,null,null,null,null,null,
    null,null,null,null,null,null,null,null,null,null,null,null,null,null,
    null,null,null,null,null,null,null,null,null,null,null,null,null,null,
    null,null,null,null,null,null,null,null,null,null,null,null,null,null,
    null,null,null,null,null,null,null,null,null,null,null,null,null,null,
    null,null,null,null,null,null,null,null,null,null,null,null,null,null,
    null,null,null,null,null,null,null,null,null,null,null,null,null,null,
    null,null,null,null,null,null,null,null,null,null,null,null,null,null,
    null,null,null,null,null,null,null,null,null,null,null,null,null,null,
    null,null,null,null,null,null,null,null,null,null,null,null,null,null,
    null,null,null,null,null,null,null,null,null,null,null,null,null,null,
    null,null,null,null,null,null,null,null,null,null,null,null,null,null,
    null,null,null,null,null,null,null,"PLUS","MINUS","MULT","DIV","EQ",
    "EQEQ","NE","GT","LS","GTEQ","LSEQ","LPAR","RPAR","LBRA","RBRA","CM",
    "SC","DOT","NUMBER","STRING","IDENT","VAR","FUNCTION","IF","ELSE",
    "WHILE","RETURN","NEW","USING","ERROR",
  };

//t  public static string yyname (int token) {
//t    if ((token < 0) || (token > yyName.Length)) return "[illegal]";
//t    string name;
//t    if ((name = yyName[token]) != null) return name;
//t    return "[unknown]";
//t  }

  /// <summary>
  /// computes list of expected tokens on error by tracing the tables.
  /// </summary>
  /// <param name="state"> for which to compute the list.</param>
  /// <returns>list of token names.</returns>
  protected string[] yyExpecting (int state) {
    int token, n, len = 0;
    bool[] ok = new bool[yyName.Length];

    if ((n = yySindex[state]) != 0)
      for (token = n < 0 ? -n : 0;
           (token < yyName.Length) && (n+token < yyTable.Length); ++ token)
        if (yyCheck[n+token] == token && !ok[token] && yyName[token] != null) {
          ++ len;
          ok[token] = true;
        }
    if ((n = yyRindex[state]) != 0)
      for (token = n < 0 ? -n : 0;
           (token < yyName.Length) && (n+token < yyTable.Length); ++ token)
        if (yyCheck[n+token] == token && !ok[token] && yyName[token] != null) {
          ++ len;
          ok[token] = true;
        }

    string [] result = new string[len];
    for (n = token = 0; n < len;  ++ token)
      if (ok[token]) result[n++] = yyName[token];
    return result;
  }

  /// <summary>
  /// the generated parser, with debugging messages.
  /// Maintains a state and a value stack, currently with fixed maximum size.
  /// </summary>
  /// <param name="yyLex"> scanner.</param>
  /// <param name="yyd"> debug message writer implementing yyDebug, or null.</param>
  /// <returns>result of the last reduction, if any.</returns>
  public Object yyparse (yyParser.yyInput yyLex, Object yyd)
				 {
//t    this.debug = (yydebug.yyDebug)yyd;
    return yyparse(yyLex);
  }

  /// <summary>
  /// initial size and increment of the state/value stack [default 256].
  /// This is not final so that it can be overwritten outside of invocations
  /// of yyparse().
  /// </summary>
  protected int yyMax;

  /// <summary>
  /// executed at the beginning of a reduce action.
  /// Used as $$ = yyDefault($1), prior to the user-specified action, if any.
  /// Can be overwritten to provide deep copy, etc.
  /// </summary>
  /// <param name="first"> value for $1, or null.</param>
  /// <returns>first.</returns>
  protected Object yyDefault (Object first) {
    return first;
  }

  /// <summary>
  /// the generated parser.
  /// Maintains a state and a value stack, currently with fixed maximum size.
  /// </summary>
  /// <param name="yyLex"> scanner</param>
  /// <returns>result of the last reduction, if any.</returns>
  public Object yyparse (yyParser.yyInput yyLex)
				{
    if (yyMax <= 0) yyMax = 256;			// initial size
    int yyState = 0;                                   // state stack ptr
    int [] yyStates = new int[yyMax];	                // state stack 
    Object yyVal = null;                               // value stack ptr
    Object [] yyVals = new Object[yyMax];	        // value stack
    int yyToken = -1;					// current input
    int yyErrorFlag = 0;				// #tks to shift

    int yyTop = 0;
    goto skip;
    yyLoop:
    yyTop++;
    skip:
    for (;; ++ yyTop) {
      if (yyTop >= yyStates.Length) {			// dynamically increase
        int[] i = new int[yyStates.Length+yyMax];
        System.Array.Copy(yyStates, i, 0);
        yyStates = i;
        Object[] o = new Object[yyVals.Length+yyMax];
        System.Array.Copy(yyVals, o, 0);
        yyVals = o;
      }
      yyStates[yyTop] = yyState;
      yyVals[yyTop] = yyVal;
//t      if (debug != null) debug.push(yyState, yyVal);

      yyDiscarded: for (;;) {	// discarding a token does not change stack
        int yyN;
        if ((yyN = yyDefRed[yyState]) == 0) {	// else [default] reduce (yyN)
          if (yyToken < 0) {
            yyToken = yyLex.advance() ? yyLex.token() : 0;
//t            if (debug != null)
//t              debug.lex(yyState, yyToken, yyname(yyToken), yyLex.value());
          }
          if ((yyN = yySindex[yyState]) != 0 && ((yyN += yyToken) >= 0)
              && (yyN < yyTable.Length) && (yyCheck[yyN] == yyToken)) {
//t            if (debug != null)
//t              debug.shift(yyState, yyTable[yyN], yyErrorFlag-1);
            yyState = yyTable[yyN];		// shift to yyN
            yyVal = yyLex.value();
            yyToken = -1;
            if (yyErrorFlag > 0) -- yyErrorFlag;
            goto yyLoop;
          }
          if ((yyN = yyRindex[yyState]) != 0 && (yyN += yyToken) >= 0
              && yyN < yyTable.Length && yyCheck[yyN] == yyToken)
            yyN = yyTable[yyN];			// reduce (yyN)
          else
            switch (yyErrorFlag) {
  
            case 0:
              yyerror(yyState,yyToken,yyLex.value(),yyExpecting(yyState));
//t              if (debug != null) debug.error("syntax error");
              goto case 1;
            case 1: case 2:
              yyErrorFlag = 3;
              do {
                if ((yyN = yySindex[yyStates[yyTop]]) != 0
                    && (yyN += Token.yyErrorCode) >= 0 && yyN < yyTable.Length
                    && yyCheck[yyN] == Token.yyErrorCode) {
//t                  if (debug != null)
//t                    debug.shift(yyStates[yyTop], yyTable[yyN], 3);
                  yyState = yyTable[yyN];
                  yyVal = yyLex.value();
                  goto yyLoop;
                }
//t                if (debug != null) debug.pop(yyStates[yyTop]);
              } while (-- yyTop >= 0);
//t              if (debug != null) debug.reject();
              throw new yyParser.yyException("irrecoverable syntax error");
  
            case 3:
              if (yyToken == 0) {
//t                if (debug != null) debug.reject();
                throw new yyParser.yyException("irrecoverable syntax error at end-of-file");
              }
//t              if (debug != null)
//t                debug.discard(yyState, yyToken, yyname(yyToken),
//t  							yyLex.value());
              yyToken = -1;
              goto yyDiscarded;		// leave stack alone
            }
        }
        int yyV = yyTop + 1-yyLen[yyN];
//t        if (debug != null)
//t          debug.reduce(yyState, yyStates[yyV-1], yyN, yyRule[yyN], yyLen[yyN]);
        yyVal = yyDefault(yyV > yyTop ? null : yyVals[yyV]);
        switch (yyN) {
case 1:
					// line 98 "Parser.jay"
  { generator.BeginProgram(); }
  break;
case 2:
					// line 98 "Parser.jay"
  { generator.EndProgram(); }
  break;
case 7:
					// line 106 "Parser.jay"
  { generator.AddStatement(generator.DeclareFunction(yyVals[0+yyTop] as CodeBlockExpression)); }
  break;
case 8:
					// line 107 "Parser.jay"
  { generator.AddStatement(yyVals[0+yyTop] as Expression); }
  break;
case 9:
					// line 109 "Parser.jay"
  { arguments.Clear(); }
  break;
case 10:
					// line 109 "Parser.jay"
  { generator.BeginFunction(yyVals[-4+yyTop] as String, arguments); }
  break;
case 11:
					// line 109 "Parser.jay"
  { yyVal = generator.EndFunction(); }
  break;
case 12:
					// line 111 "Parser.jay"
  { arguments.Clear(); }
  break;
case 13:
					// line 111 "Parser.jay"
  { generator.BeginFunction(null, arguments); }
  break;
case 14:
					// line 111 "Parser.jay"
  { yyVal = generator.EndFunction(); }
  break;
case 17:
					// line 116 "Parser.jay"
  { arguments.Add(yyVals[0+yyTop] as String); }
  break;
case 18:
					// line 117 "Parser.jay"
  { arguments.Add(yyVals[0+yyTop] as String); }
  break;
case 19:
					// line 119 "Parser.jay"
  { generator.BeginBlock(); }
  break;
case 23:
					// line 124 "Parser.jay"
  { generator.AddStatement(yyVals[0+yyTop] as Expression); }
  break;
case 24:
					// line 125 "Parser.jay"
  { generator.AddStatement(yyVals[0+yyTop] as Expression); }
  break;
case 25:
					// line 127 "Parser.jay"
  { yyVal = yyVals[0+yyTop]; }
  break;
case 26:
					// line 128 "Parser.jay"
  { yyVal = yyVals[0+yyTop]; }
  break;
case 27:
					// line 129 "Parser.jay"
  { yyVal = yyVals[0+yyTop]; }
  break;
case 28:
					// line 130 "Parser.jay"
  { yyVal = yyVals[0+yyTop]; }
  break;
case 29:
					// line 131 "Parser.jay"
  { yyVal = yyVals[0+yyTop]; }
  break;
case 30:
					// line 132 "Parser.jay"
  { yyVal = yyVals[0+yyTop]; }
  break;
case 31:
					// line 133 "Parser.jay"
  { yyVal = yyVals[0+yyTop]; }
  break;
case 32:
					// line 135 "Parser.jay"
  { yyVal = generator.UsingLibrary(yyVals[-1+yyTop] as String); }
  break;
case 33:
					// line 137 "Parser.jay"
  { yyVal = generator.DeclareVariable(yyVals[-2+yyTop] as String, yyVals[-1+yyTop] as Expression); }
  break;
case 34:
					// line 139 "Parser.jay"
  { yyVal = yyVals[0+yyTop]; }
  break;
case 35:
					// line 140 "Parser.jay"
  { yyVal = null; }
  break;
case 36:
					// line 142 "Parser.jay"
  { yyVal = generator.AssignVariable(yyVals[-3+yyTop] as String, yyVals[-1+yyTop] as Expression); }
  break;
case 37:
					// line 143 "Parser.jay"
  { yyVal = generator.AssignMember(yyVals[-5+yyTop] as Expression, yyVals[-3+yyTop] as String, yyVals[-1+yyTop] as Expression); }
  break;
case 38:
					// line 145 "Parser.jay"
  { yyVal = generator.EndBlock(); }
  break;
case 39:
					// line 145 "Parser.jay"
  { yyVal = generator.IfElse(yyVals[-5+yyTop] as Expression, yyVals[-2+yyTop] as Expression, generator.EndBlock()); }
  break;
case 40:
					// line 146 "Parser.jay"
  { yyVal = generator.IfElse(yyVals[-2+yyTop] as Expression, generator.EndBlock(), null); }
  break;
case 41:
					// line 148 "Parser.jay"
  { generator.BeginListExpr(); }
  break;
case 42:
					// line 148 "Parser.jay"
  { yyVal = generator.FunctionCall(yyVals[-4+yyTop] as String, generator.EndListExpr()); }
  break;
case 43:
					// line 149 "Parser.jay"
  { generator.BeginListExpr(); }
  break;
case 44:
					// line 149 "Parser.jay"
  { yyVal = generator.MethodCall(yyVals[-6+yyTop] as Expression, yyVals[-4+yyTop] as String, generator.EndListExpr()); }
  break;
case 45:
					// line 151 "Parser.jay"
  { generator.BeginListExpr(); }
  break;
case 46:
					// line 151 "Parser.jay"
  { yyVal = generator.NewObject(yyVals[-4+yyTop] as String, generator.EndListExpr()); }
  break;
case 47:
					// line 152 "Parser.jay"
  { yyVal = generator.NewObject(); }
  break;
case 48:
					// line 154 "Parser.jay"
  { yyVal = generator.Statement(yyVals[-1+yyTop] as Expression); }
  break;
case 49:
					// line 156 "Parser.jay"
  { yyVal = generator.While(yyVals[-2+yyTop] as Expression, generator.EndBlock()); }
  break;
case 50:
					// line 158 "Parser.jay"
  { yyVal = generator.Return(yyVals[-1+yyTop] as Expression); }
  break;
case 51:
					// line 159 "Parser.jay"
  { yyVal = generator.Return(null); }
  break;
case 53:
					// line 162 "Parser.jay"
  { generator.BeginBlock(); generator.AddStatement(yyVals[0+yyTop] as Expression); }
  break;
case 54:
					// line 164 "Parser.jay"
  { yyVal = generator.BinaryOperator(yyVals[-2+yyTop] as Expression, Operators.Equals, yyVals[0+yyTop] as Expression); }
  break;
case 55:
					// line 165 "Parser.jay"
  { yyVal = generator.BinaryOperator(yyVals[-2+yyTop] as Expression, Operators.NotEquals, yyVals[0+yyTop] as Expression); }
  break;
case 56:
					// line 166 "Parser.jay"
  { yyVal = generator.BinaryOperator(yyVals[-2+yyTop] as Expression, Operators.GreaterThan, yyVals[0+yyTop] as Expression); }
  break;
case 57:
					// line 167 "Parser.jay"
  { yyVal = generator.BinaryOperator(yyVals[-2+yyTop] as Expression, Operators.LessThan, yyVals[0+yyTop] as Expression); }
  break;
case 58:
					// line 168 "Parser.jay"
  { yyVal = generator.BinaryOperator(yyVals[-2+yyTop] as Expression, Operators.GreaterThanOrEqual, yyVals[0+yyTop] as Expression); }
  break;
case 59:
					// line 169 "Parser.jay"
  { yyVal = generator.BinaryOperator(yyVals[-2+yyTop] as Expression, Operators.LessThanOrEqual, yyVals[0+yyTop] as Expression); }
  break;
case 60:
					// line 171 "Parser.jay"
  { yyVal = generator.BinaryOperator(yyVals[-2+yyTop] as Expression, Operators.Add, yyVals[0+yyTop] as Expression); }
  break;
case 61:
					// line 172 "Parser.jay"
  { yyVal = generator.BinaryOperator(yyVals[-2+yyTop] as Expression, Operators.Multiply, yyVals[0+yyTop] as Expression); }
  break;
case 62:
					// line 173 "Parser.jay"
  { yyVal = generator.BinaryOperator(yyVals[-2+yyTop] as Expression, Operators.Subtract, yyVals[0+yyTop] as Expression); }
  break;
case 63:
					// line 174 "Parser.jay"
  { yyVal = generator.BinaryOperator(yyVals[-2+yyTop] as Expression, Operators.Divide, yyVals[0+yyTop] as Expression); }
  break;
case 64:
					// line 175 "Parser.jay"
  { yyVal = yyVals[0+yyTop]; }
  break;
case 65:
					// line 176 "Parser.jay"
  { yyVal = yyVals[0+yyTop]; }
  break;
case 66:
					// line 177 "Parser.jay"
  { yyVal = yyVals[0+yyTop]; }
  break;
case 67:
					// line 178 "Parser.jay"
  { yyVal = yyVals[0+yyTop]; }
  break;
case 68:
					// line 179 "Parser.jay"
  { yyVal = yyVals[0+yyTop]; }
  break;
case 69:
					// line 181 "Parser.jay"
  { yyVal = generator.NumberConstant((int)yyVals[0+yyTop]); }
  break;
case 70:
					// line 182 "Parser.jay"
  { yyVal = generator.StringConstant(yyVals[0+yyTop] as String); }
  break;
case 71:
					// line 184 "Parser.jay"
  { yyVal = generator.Variable(yyVals[0+yyTop] as String); }
  break;
case 72:
					// line 185 "Parser.jay"
  { yyVal = generator.Member(yyVals[-2+yyTop] as Expression, yyVals[0+yyTop] as String); }
  break;
case 75:
					// line 190 "Parser.jay"
  { generator.AddExpression(yyVals[0+yyTop] as Expression); }
  break;
case 76:
					// line 191 "Parser.jay"
  { generator.AddExpression(yyVals[0+yyTop] as Expression); }
  break;
					// line 597 "-"
        }
        yyTop -= yyLen[yyN];
        yyState = yyStates[yyTop];
        int yyM = yyLhs[yyN];
        if (yyState == 0 && yyM == 0) {
//t          if (debug != null) debug.shift(0, yyFinal);
          yyState = yyFinal;
          if (yyToken < 0) {
            yyToken = yyLex.advance() ? yyLex.token() : 0;
//t            if (debug != null)
//t               debug.lex(yyState, yyToken,yyname(yyToken), yyLex.value());
          }
          if (yyToken == 0) {
//t            if (debug != null) debug.accept(yyVal);
            return yyVal;
          }
          goto yyLoop;
        }
        if (((yyN = yyGindex[yyM]) != 0) && ((yyN += yyState) >= 0)
            && (yyN < yyTable.Length) && (yyCheck[yyN] == yyState))
          yyState = yyTable[yyN];
        else
          yyState = yyDgoto[yyM];
//t        if (debug != null) debug.shift(yyStates[yyTop], yyState);
	 goto yyLoop;
      }
    }
  }

   static  short [] yyLhs  = {              -1,
    2,    0,    1,    1,    3,    3,    4,    4,    7,   10,
    5,   12,   13,   11,    8,    8,   14,   14,   16,    9,
   15,   15,   17,   17,    6,    6,    6,    6,    6,    6,
    6,   18,   19,   25,   25,   20,   20,   29,   21,   21,
   32,   30,   33,   30,   35,   34,   34,   23,   22,   24,
   24,   28,   28,   27,   27,   27,   27,   27,   27,   26,
   26,   26,   26,   26,   26,   26,   26,   26,   36,   36,
   37,   37,   31,   31,   38,   38,
  };
   static  short [] yyLen = {           2,
    0,    2,    1,    0,    2,    1,    1,    1,    0,    0,
    8,    0,    0,    7,    1,    0,    3,    1,    0,    4,
    1,    0,    2,    1,    1,    1,    1,    1,    1,    1,
    1,    3,    4,    2,    0,    4,    6,    0,    8,    5,
    0,    5,    0,    7,    0,    6,    2,    2,    5,    3,
    2,    1,    1,    3,    3,    3,    3,    3,    3,    3,
    3,    3,    3,    1,    1,    1,    1,    1,    1,    1,
    1,    3,    1,    0,    3,    1,
  };
   static  short [] yyDefRed = {            1,
    0,    0,    0,   69,   70,    0,    0,    0,    0,    0,
    0,    0,    0,    2,    0,    6,    7,    8,   65,   25,
   26,   27,   28,   29,   30,   31,    0,    0,   66,   67,
   68,   47,    0,   41,    0,    9,    0,    0,    0,   51,
    0,   12,    0,   64,    0,    0,    5,    0,    0,    0,
    0,    0,   48,    0,    0,    0,    0,    0,    0,    0,
    0,    0,   50,    0,   45,   32,    0,    0,    0,    0,
    0,   36,    0,    0,    0,    0,   33,    0,   18,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,   43,   42,    0,    0,   13,    0,    0,    0,
    0,    0,    0,    0,    0,   53,   52,    0,   49,    0,
    0,    0,    0,   10,    0,   17,    0,    0,   46,   37,
    0,    0,   19,   14,   24,    0,    0,    0,   44,   11,
   20,   23,   39,
  };
  protected static  short [] yyDgoto  = {             1,
   14,    2,   15,   16,   17,  106,   58,   80,  107,  122,
   19,   37,  115,   81,  126,  117,  127,   20,   21,   22,
   23,   24,   25,   26,   57,   27,   61,  108,  118,   44,
   74,   55,  112,   29,   91,   30,   31,   75,
  };
  protected static  short [] yySindex = {            0,
    0,  -36, -266,    0,    0, -234, -271, -270, -250, -240,
   -9, -244, -235,    0,  -36,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0, -237, -224,    0,    0,
    0,    0,   39,    0, -217,    0, -218,   39,   39,    0,
 -210,    0, -248,    0, -201, -222,    0,   39,   39,   39,
   39, -212,    0, -183,   39,   39, -205, -196, -204, -127,
 -191, -184,    0, -178,    0,    0, -245, -245, -181, -181,
 -230,    0, -109, -175, -166, -109,    0, -204,    0, -161,
 -159,   39,   39,   39,   39,   39,   39,  -25,  -25, -154,
   39,   39,    0,    0,   39, -153,    0, -160, -109, -109,
 -109, -109, -109, -109, -266,    0,    0,    0,    0, -151,
 -116,   39, -109,    0, -150,    0,   17, -158,    0,    0,
 -148, -150,    0,    0,    0, -149,   17,  -25,    0,    0,
    0,    0,    0,
  };
  protected static  short [] yyRindex = {            0,
    0,  124,    0,    0,    0, -105,    0, -141,    0,    0,
    0,    0,    0,    0,  128,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,  -98,    0,    0,
    0,    0,    0,    0, -139,    0,    0,    0,    0,    0,
 -203,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0, -124,    0,    0,    0, -123,    0,
    0,    0,    0,    0,    0,    0,  -50,  -37,  -80,  -63,
  -86,    0, -253,    0, -113, -110,    0, -123,    0,    0,
 -103,    0,    0,    0,    0,    0,    0,    0,    0, -162,
 -124,    0,    0,    0,    0,    0,    0,    0, -102, -101,
  -99,  -94,  -79,  -78,   28,    0,    0,    1,    0,    0,
    0, -124, -229,    0,    0,    0, -107,    0,    0,    0,
    0,    0,    0,    0,    0,    0,  -90,    0,    0,    0,
    0,    0,    0,
  };
  protected static  short [] yyGindex = {            0,
    0,    0,    0,  183,    0,    2,    0,  127,  -83,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,   -3,  172,  -87,    0,   -2,
  -88,    0,    0,    0,    0,    0,    0,    0,
  };
  protected static  short [] yyTable = {            28,
   40,  109,  110,   18,   32,   35,   36,   43,   48,   49,
   50,   51,   28,   50,   51,   76,   18,   38,   76,   48,
   49,   50,   51,  121,   63,   64,   33,   39,   64,   54,
   92,  124,   45,   34,   60,   60,   52,   93,  130,   75,
  133,   46,   75,   56,   67,   68,   69,   70,   53,   59,
   66,   73,   76,   71,   71,   71,   71,   34,   71,   71,
   71,   71,   71,   71,   71,   71,   65,   77,   71,   71,
   71,   78,   79,   48,   49,   50,   51,   88,   99,  100,
  101,  102,  103,  104,   89,   28,   28,   73,  111,   72,
   64,  113,   64,   94,   72,   72,   72,   72,   90,   72,
   72,   72,   72,   72,   72,   95,   72,   97,   73,   72,
   72,   72,   98,   93,   28,  114,  116,  119,  125,  123,
  129,  131,  128,    4,   28,   28,   12,    3,  132,   48,
   49,   50,   51,   35,   82,   83,   84,   85,   86,   87,
   48,   49,   50,   51,   74,   16,   64,   48,   49,   50,
   51,   71,   71,   71,   71,   73,  120,   64,   64,   64,
   64,   64,   34,   22,   64,   15,   54,   55,   71,   56,
   72,   72,   72,   72,   57,   64,   61,   61,   61,   61,
   21,   61,   61,   61,   61,   61,   61,   72,   61,   58,
   59,   61,   61,   63,   63,   63,   63,   47,   63,   63,
   63,   63,   63,   63,   96,   63,   60,   60,   63,   63,
   62,   60,   60,   60,   60,   60,   60,    0,   60,   62,
   62,   60,   60,    0,   62,   62,   62,   62,   62,   62,
    0,   62,    0,    3,   62,   62,    0,    0,    4,    5,
    6,    7,    8,    9,  105,   10,   11,   12,   13,    4,
    5,    6,    7,   42,    9,    0,   10,   11,   12,   13,
    3,    0,    0,   40,    0,    4,    5,   41,    0,   42,
   40,   40,    0,    0,   12,   40,   40,   40,   40,   40,
   40,   38,   40,   40,   40,   40,    3,    0,    0,    0,
    0,    4,    5,    6,    7,   42,    9,   19,   10,   11,
   12,   13,   19,   19,   19,   19,   19,   19,    3,   19,
   19,   19,   19,    4,    5,   41,    0,   42,    0,    0,
    0,    0,   12,
  };
  protected static  short [] yyCheck = {             2,
    0,   89,   91,    2,  271,  277,  277,   11,  257,  258,
  259,  260,   15,  259,  260,  269,   15,  268,  272,  257,
  258,  259,  260,  112,  273,  274,  261,  268,  274,   33,
  261,  115,  277,  268,   38,   39,  274,  268,  122,  269,
  128,  277,  272,  261,   48,   49,   50,   51,  273,  268,
  273,   55,   56,  257,  258,  259,  260,  268,  262,  263,
  264,  265,  266,  267,  277,  269,  268,  273,  272,  273,
  274,  268,  277,  257,  258,  259,  260,  269,   82,   83,
   84,   85,   86,   87,  269,   88,   89,   91,   92,  273,
  274,   95,  274,  269,  257,  258,  259,  260,  277,  262,
  263,  264,  265,  266,  267,  272,  269,  269,  112,  272,
  273,  274,  272,  268,  117,  269,  277,  269,  117,  270,
  269,  271,  281,    0,  127,  128,  268,    0,  127,  257,
  258,  259,  260,  273,  262,  263,  264,  265,  266,  267,
  257,  258,  259,  260,  269,  269,  274,  257,  258,  259,
  260,  257,  258,  259,  260,  269,  273,  274,  257,  258,
  259,  260,  273,  271,  274,  269,  269,  269,  274,  269,
  257,  258,  259,  260,  269,  274,  257,  258,  259,  260,
  271,  262,  263,  264,  265,  266,  267,  274,  269,  269,
  269,  272,  273,  257,  258,  259,  260,   15,  262,  263,
  264,  265,  266,  267,   78,  269,  257,  258,  272,  273,
   39,  262,  263,  264,  265,  266,  267,   -1,  269,  257,
  258,  272,  273,   -1,  262,  263,  264,  265,  266,  267,
   -1,  269,   -1,  270,  272,  273,   -1,   -1,  275,  276,
  277,  278,  279,  280,  270,  282,  283,  284,  285,  275,
  276,  277,  278,  279,  280,   -1,  282,  283,  284,  285,
  270,   -1,   -1,  273,   -1,  275,  276,  277,   -1,  279,
  270,  271,   -1,   -1,  284,  275,  276,  277,  278,  279,
  280,  281,  282,  283,  284,  285,  270,   -1,   -1,   -1,
   -1,  275,  276,  277,  278,  279,  280,  270,  282,  283,
  284,  285,  275,  276,  277,  278,  279,  280,  270,  282,
  283,  284,  285,  275,  276,  277,   -1,  279,   -1,   -1,
   -1,   -1,  284,
  };

					// line 194 "Parser.jay"


    /// <summary>
	/// Current tokenizer
	/// </summary>
	private Lexer lexer;
		
	
	/// <summary>
	/// Constructor with a source.
	/// </summary>	
	public Parser(SourceUnit source)
	{
		lexer = new Lexer(source);
		report = new Report();
		generator = new Generator(report, lexer.Location);
        arguments = new List<string>();
        result = null;	    
    }
	
	/// <summary>
	/// Parse the input.
	/// </summary>
	/// <returns>true if no error, false else</returns>
	public override bool Parse()
	{
		// Do parsing, to debug: set yacc_verbose_flag and replace "//t" comment by "" in C# parser file
		try {
			if (yacc_verbose_flag)
				yyparse(lexer, new yydebug.yyDebugSimple ());
			else
				yyparse(lexer);
			result = generator.Result.MakeLambda();
		} 
		catch(yyParser.yyException)
		{
		}
		catch (SyntaxErrorException)
		{
			throw;
		}	    
		catch (Exception e)
		{	
			report.Error(lexer.Location, Report.FatalError, e.ToString());
		}
		
		return true;
	}
}
					// line 828 "-"
namespace yydebug {
        using System;
	 public interface yyDebug {
        /// <summary>
        /// Push a state an its value.
        /// </summary>
        /// <param name="state">state to push</param>
        /// <param name="value">state value</param>
		 void push (int state, Object value);

        /// <summary>
        /// Get a token.
        /// </summary>
        /// <param name="state">state</param>
        /// <param name="token">token</param>
        /// <param name="name">name</param>
        /// <param name="value">state value</param>
		 void lex (int state, int token, string name, Object value);
		 
        /// <summary>
        /// Advance from a state.
        /// </summary>
        /// <param name="from">start state</param>
        /// <param name="to">end state</param>
        /// <param name="errorFlag">error flag</param>
		 void shift (int from, int to, int errorFlag);
		 
        /// <summary>
        /// Pop a state.
        /// </summary>
        /// <param name="state">state</param>
		 void pop (int state);
		 
        /// <summary>
        /// Discard state.
        /// </summary>
        /// <param name="state">state</param>
        /// <param name="token">token</param>
        /// <param name="name">name</param>
        /// <param name="value">state value</param>
		 void discard (int state, int token, string name, Object value);
		 
        /// <summary>
        /// Reduce state.
        /// </summary>
        /// <param name="from">from</param>
        /// <param name="to">to</param>
        /// <param name="rule">rule</param>
        /// <param name="text">text</param>
        /// <param name="len">len</param>
		 void reduce (int from, int to, int rule, string text, int len);
		 
        /// <summary>
        /// Advance from a state.
        /// </summary>
        /// <param name="from">start state</param>
        /// <param name="to">end state</param>
		 void shift (int from, int to);
		 
        /// <summary>
        /// Accept state.
        /// </summary>
        /// <param name="value">value</param>
		 void accept (Object value);
		
        /// <summary>
        /// Error.
        /// </summary>
        /// <param name="message">message</param> 
		 void error (string message);
		 
        /// <summary>
        /// Reject state.
        /// </summary>
		 void reject ();
	 }
	
    /// <summary>
    /// Single debug class.
    /// </summary> 
	 class yyDebugSimple : yyDebug {
        /// <summary>
        /// Print string on a new line.
        /// </summary>
        /// <param name="s">string to print</param>
		 void println (string s){
			 Console.Error.WriteLine(s);
		 }
		 
        /// <summary>
        /// Push a state an its value.
        /// </summary>
        /// <param name="state">state to push</param>
        /// <param name="value">state value</param>
		 public void push (int state, Object value) {
			 println("push\tstate "+state+"\tvalue "+value);
		 }

        /// <summary>
        /// Get a token.
        /// </summary>
        /// <param name="state">state</param>
        /// <param name="token">token</param>
        /// <param name="name">name</param>
        /// <param name="value">state value</param>	 
		 public void lex (int state, int token, string name, Object value) {
			 println("lex\tstate "+state+"\treading "+name+"\tvalue "+value);
		 }
		 
        /// <summary>
        /// Advance from a state.
        /// </summary>
        /// <param name="from">start state</param>
        /// <param name="to">end state</param>
        /// <param name="errorFlag">error flag</param>
		 public void shift (int from, int to, int errorFlag) {
			 switch (errorFlag) {
			 default:				// normally
				 println("shift\tfrom state "+from+" to "+to);
				 break;
			 case 0: case 1: case 2:		// in error recovery
				 println("shift\tfrom state "+from+" to "+to
					     +"\t"+errorFlag+" left to recover");
				 break;
			 case 3:				// normally
				 println("shift\tfrom state "+from+" to "+to+"\ton error");
				 break;
			 }
		 }
		 
        /// <summary>
        /// Pop a state.
        /// </summary>
        /// <param name="state">state</param>
		 public void pop (int state) {
			 println("pop\tstate "+state+"\ton error");
		 }
		 
        /// <summary>
        /// Discard state.
        /// </summary>
        /// <param name="state">state</param>
        /// <param name="token">token</param>
        /// <param name="name">name</param>
        /// <param name="value">state value</param>
		 public void discard (int state, int token, string name, Object value) {
			 println("discard\tstate "+state+"\ttoken "+name+"\tvalue "+value);
		 }
		 
        /// <summary>
        /// Reduce state.
        /// </summary>
        /// <param name="from">from</param>
        /// <param name="to">to</param>
        /// <param name="rule">rule</param>
        /// <param name="text">text</param>
        /// <param name="len">len</param>
		 public void reduce (int from, int to, int rule, string text, int len) {
			 println("reduce\tstate "+from+"\tuncover "+to
				     +"\trule ("+rule+") "+text);
		 }
		 
        /// <summary>
        /// Shift state.
        /// </summary>
        /// <param name="from">start state</param>
        /// <param name="to">end state</param>
		 public void shift (int from, int to) {
			 println("goto\tfrom state "+from+" to "+to);
		 }
		 
        /// <summary>
        /// Accept state.
        /// </summary>
        /// <param name="value">value</param>
		 public void accept (Object value) {
			 println("accept\tvalue "+value);
		 }
		
        /// <summary>
        /// Error.
        /// </summary>
        /// <param name="message">message</param> 
		 public void error (string message) {
			 println("error\t"+message);
		 }
		 
        /// <summary>
        /// Reject state.
        /// </summary>
		 public void reject () {
			 println("reject");
		 }
		 
	 }
}
 /// <summary>
 /// Token constants.
 /// </summary>
 public class Token {
  public const int EOF = 0;
  public const int PLUS = 257;
  public const int MINUS = 258;
  public const int MULT = 259;
  public const int DIV = 260;
  public const int EQ = 261;
  public const int EQEQ = 262;
  public const int NE = 263;
  public const int GT = 264;
  public const int LS = 265;
  public const int GTEQ = 266;
  public const int LSEQ = 267;
  public const int LPAR = 268;
  public const int RPAR = 269;
  public const int LBRA = 270;
  public const int RBRA = 271;
  public const int CM = 272;
  public const int SC = 273;
  public const int DOT = 274;
  public const int NUMBER = 275;
  public const int STRING = 276;
  public const int IDENT = 277;
  public const int VAR = 278;
  public const int FUNCTION = 279;
  public const int IF = 280;
  public const int ELSE = 281;
  public const int WHILE = 282;
  public const int RETURN = 283;
  public const int NEW = 284;
  public const int USING = 285;
  public const int ERROR = 286;
  public const int yyErrorCode = 256;
 }
 namespace yyParser {
  using System;
 /// <summary>
 /// Thrown for irrecoverable syntax errors and stack overflow.
 /// </summary>
  public class yyException : System.Exception {
    /// <summary>
    /// Exception.
    /// </summary>
    /// <param name="message">message</param>
    public yyException (string message) : base (message) {
    }
  }

 /// <summary>
 /// Must be implemented by a scanner object to supply input to the parser.
 /// </summary>
  public interface yyInput {
    /// <summary>
    /// Move on to next token.
    /// </summary>
	 /// <returns>false if positioned beyond tokens</returns>
    bool advance (); // throws java.io.IOException;

    /// <summary>
    /// Classifies current token. Should not be called if advance() returned false.
    /// </summary>
	 /// <returns>current %token or single character</returns>
    int token ();

    /// <summary>
    /// Associated with current token. Should not be called if advance() returned false.
    /// </summary>
	 /// <returns>value for token()</returns>
    Object value ();
  }
 }
} // close outermost namespace, that MUST HAVE BEEN opened in the prolog
//#if net_2_0
//#pragma warning restore 1591, 162
//#endif
